package com.vitabuybuy.tv.ui.shopcenter.store

import android.os.Bundle
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import com.library.common.base.BaseActivity
import com.library.common.base.BaseViewModel
import com.tencent.rtmp.TXLiveConstants
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.adaptebinding.ImageAdapter
import com.vitabuybuy.tv.databinding.ActivityLiveRecallbackBinding
import com.vitabuybuy.tv.dialog.SharePopup
import com.vitabuybuy.tv.dto.ReCallBackBean
import com.vitabuybuy.tv.ui.tencent.superplay.PlaybackFragment


/**
 * 作者：SimGa
 * 日期：2021/5/5
 * 时间：23:47
 * 包名：com.vitabuybuy.tv.ui.tencent
 */

class LiveReCallBackActivity : BaseActivity<BaseViewModel, ActivityLiveRecallbackBinding>() {
    override val isUseBaseTitleBar: Boolean
        get() = false
    override val layoutId: Int
        get() = R.layout.activity_live_recallback

    private var liveBean: ReCallBackBean? = null
    private var playback: PlaybackFragment? = null

    override fun onGetBundle(bundle: Bundle?) {
        liveBean = bundle?.getSerializable("liveBean") as ReCallBackBean
    }

    override fun initView(savedInstanceState: Bundle?) {
        playback = PlaybackFragment()
        liveBean?.let {
            ImageAdapter.setCircleImageUrl(
                mBinding.ivAuthorAvatar, it.authorAvatar, ContextCompat.getDrawable(
                    mContext,
                    R.drawable.beauty_ic_makeups_widow
                )
            )
            mBinding.btnFollow.text =
                if (it.attention!!) getString(R.string.already_success_follow) else getString(R.string.follow)
            mBinding.tvStoreName.text = it.authorName
            mBinding.tvAuthorId.text = "ID : ${it.authorId}"
            mBinding.tvRegion.text = String.format(
                getString(R.string.mlvb_view_count_region),
                it.audienceCount,
                it.authorRegion
            )
            playback?.run {
                this.setUrl(it.mCoverUrl, it.playUrl, true)
//                seek?.let {
//                    this.seek(it)
//                }
                this.allShowControl = true
                this.showFill = false
                this.mRenderMode = TXLiveConstants.RENDER_MODE_ADJUST_RESOLUTION
                this.mRenderRotation = intent.getIntExtra("RenderRotation", -1)
                supportFragmentManager.beginTransaction()
                    .add(R.id.containerFragment, this, "playback").commitAllowingStateLoss()
            }
        }
    }

    override fun eventHandling() {
        mBinding.btnClose.setOnClickListener {
            finish()
        }
        mBinding.btnShare.setOnClickListener {
            SharePopup(mContext).showPopupWindow()
        }
        mBinding.btnMore.setOnClickListener {
            if (mBinding.ivJubao.visibility == View.INVISIBLE) {
                mBinding.ivJubao.visibility = View.VISIBLE
            } else {
                mBinding.ivJubao.visibility = View.INVISIBLE
            }
        }
    }

    companion object {
        fun openActivity(
            mContext: BaseActivity<*, *>,
            liveBean: ReCallBackBean
        ) {
            mContext.startActivity(
                bundleOf(
                    Pair("liveBean", liveBean)
                ),
                LiveReCallBackActivity::class.java
            )
        }
    }
}